package com.atguigu.lease.web.service.impl;

import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.mapper.SystemUserMapper;
import com.atguigu.lease.web.service.SystemUserService;
import com.atguigu.lease.web.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
@Transactional
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Override
    public void customQueryPage(Page<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        this.baseMapper.customQueryPage(page, queryVo);
    }

    @Override
    public SystemUserItemVo customGetById(Long id) {
        return this.baseMapper.customGetById(id);
    }

    @Override
    public void customSaveOrUpdate(SystemUser systemUser) {
        if (StringUtils.isNotEmpty(systemUser.getPassword())) {
            // 密码加密
            String md5 = DigestUtils.md5Hex(systemUser.getPassword());
            systemUser.setPassword(md5);
        }
        this.saveOrUpdate(systemUser);
    }
}




